using UnityEngine;

namespace BridgeShips.AI {
    public class Break : Action {
        [SerializeField]
        [Clamp( 0f, 100f )]
        private float m_MinBreakDistance = 3.0f;

        private Vector3 m_BreakPosition;

        public override void OnStart( AIShip ship ) {
            m_Priority = 10;
            m_IsInterruptable = true;
            m_RepeatType = ET.ActionRepeatType.Single;

            Preconditions.Add( HelpStrings.AI.IS_SHIP_IN_SIGHT, true );

            Effects.Add( HelpStrings.AI.IS_SHIP_IN_SIGHT, false );
        }

        public override bool CanActivate( AIShip ship ) {
            if (ship.Settings.Detection.HasTarget()) {
                Vector3 shipPos = ship.transform.position;
                var target = ship.Settings.Detection.GetRandomTarget();
                Vector3 targetPos = Vector3.zero;
                if (target != null) {
                    targetPos = ship.Settings.Detection.GetRandomTarget().Position();
                }

                return (shipPos - targetPos).magnitude < m_MinBreakDistance;
            }

            return false;
        }

        public override void Activate( AIShip ship ) {

        }

        public override void OnUpdate( AIShip ship ) {
            Vector3 aiPos = ship.transform.position;


        }

        public override void OnDeactivation( AIShip ship ) {

        }

        public override bool StillValid( AIShip ship ) {
            return ship.Settings.Detection.HasTarget();
        }

        public override bool IsDone( AIShip ship ) {
            return !ship.Settings.Detection.HasTarget();
        }
    }
}